<html>
<head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
 	<meta http-equiv="expires" content="Thu, 01 Jan 1970 00:00:00 GMT">
	<meta http-equiv="cache-control" content="no-store, no-cache, must-revalidate">
	<meta http-equiv="content-style-type" content='text/css' />
	<meta http-equiv="content-language" content="ua" />
	<meta http-equiv="pragma" content="no-cache">


<title>Информационный дайджест</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
<script type="text/javascript" src="common.js"></script>
<style type="text/css">
        #chan_items { margin: 20px; }
        #chan_items #item { margin-bottom: 10px; }
        #chan_items #item #item_title { font-weight: bold; }
    </style>

</head>
<body id="main_body" >
	
	<img id="top" src="top.png" alt="">
	<div id="form_container">
	
		<h1><a>Информационный дайджест</a></h1>
		<form id="form_123080" class="appnitro"  method="post" accept-charset="utf-8" action="javascript:getRSS()" lang="ru">
					<div class="form_description">
			<h2>Информационный дайджест</h2>
			<p></p>
		</div>						
			<ul >
			
					<li id="li_1" >
		<label class="description" for="element_1">Ключевые слова </label>
		<div>
			<input id="keywords" name="keywords" class="element text medium" type="text" maxlength="255" value=""/>					  
            <DIV id="status"/> 
		</div><p class="guidelines" id="guide_1"><small>1) логическое "И" - знак & либо просто пробел
2) логическое "ИЛИ" - знак |
3) логическое "Нет" - знак "-" либо знак "!"
4) строгое соответствие - кавычки ""
5) поиск с расстоянием</small></p> 
		</li>		<li id="li_2" >
		<label class="description" for="element_2">Формат вывода </label>
		<span>
			<input id="fulltext" name="fulltext" class="element radio" type="radio" value="1" checked="checked" />
<label class="choice" for="element_2_1">Полный текст</label>
<input id="fulltext" name="fulltext" class="element radio" type="radio" value="0" />
<label class="choice" for="element_2_2">Выдержки</label>

		</span> 
		</li>
			
					<li class="buttons">
			    <input type="hidden" name="form_id" value="123080" />
			    
				<input id="saveForm" class="button_text" type="submit" name="submit" value="Мониторить" />
		</li>
			</ul>
		</form>
		<DIV id="status2"/></div>
		<div id="chan">
        <div id="chan_title"></div>
        <div id="chan_link"></div>
        <div id="chan_description"></div>
        <a id="chan_image_link" href=""></a>
        <div id="chan_items"></div>
        <div id="chan_pubDate"></div>
        <div id="chan_copyright"></div>
    </div>	
		<!-- div id="footer">
			Generated by <a href="http://www.phpform.org">pForm</a>
		</div -->
	</div>
	
	<img id="bottom" src="bottom.png" alt="">
	
	<script type="text/javascript">
	    var http;
	    var ret;

	    function getRSS() {

	        //var keywords = Utf8.encode($("keywords").value);
	        var keywords =  encodeURIComponent($("keywords").value);
	        //var keywords = $("keywords");
	        var fulltext = "";
	        if ($("fulltext").checked == true)
	            fulltext = "fulltext=1&";
	    

	        $("keywords").disabled = true;
	        $("fulltext").disabled = true;
	        $("saveForm").disabled = true;

	        //var url = "search_mon.php?" + fulltext + "query=" + keywords;
	        //var url = "rss-direct.php?" + fulltext + "query=" + keywords;
          var url = "rss-direct.php?" + fulltext + "query=" + keywords + "&query_meta=" + keywords + "&query_mx=" + keywords;
			//var url = "search_mon.php?" + fulltext + "query=" + encodeURIComponent(keywords);

	        /*A*/
	        if (window.ActiveXObject) //IE
	            xhr = new ActiveXObject("Microsoft.XMLHTTP");
	        else if (window.XMLHttpRequest) //other
	            xhr = new XMLHttpRequest();
	        else
	            alert("your browser does not support AJAX");

	        /*B*/
	        xhr.open("GET", url, true);

	        /*C*/
	        xhr.setRequestHeader("Cache-Control", "no-cache");
	        xhr.setRequestHeader("Pragma", "no-cache");
	        xhr.setRequestHeader("Encoding", "utf-8");
	        xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 

	        /*D*/
	        xhr.onreadystatechange = function() {
	        if (xhr.readyState == 4) {
	            $("keywords").disabled = false;
	            $("fulltext").disabled = false;
	            $("saveForm").disabled = false;
	                if (xhr.status == 200) {
	                    /*F*/
	                    if (xhr.responseText != null) {
	                        //processRSS(xhr.responseXML);
							//alert(xhr.responseText);
	                        $("status2").innerHTML = "<span style='padding:10px;'>" +
                          xhr.responseText +
                          "</span>";
							//$("status").innerHTML = "<span style='color:red'><b>" + xhr.responseText + "</b></span>";
	                    } else {
	                        alert("Failed to receive RSS file from the server - error occured.");
	                        return false;
	                    }
	                }
	                else
	                    alert("Error code " + xhr.status + " received: " + xhr.statusText);
	            }
	           
	        }

	        /*E*/
	        xhr.send(null);
	    }
	    
	    function processRSS(rssxml) {
	    
	        
	        RSS = new RSS2Channel(rssxml);
	        showRSS(RSS);
	    }

	    function RSS2Enclosure(encElement) {
	        if (encElement == null) {
	            this.url = null;
	            this.length = null;
	            this.type = null;
	        } else {
	            this.url = encElement.getAttribute("url");
	            this.length = encElement.getAttribute("length");
	            this.type = encElement.getAttribute("type");
	        }
	    }
	    function RSS2Image(imgElement) {
	        if (imgElement == null) {
	            this.url = null;
	            this.link = null;
	            this.width = null;
	            this.height = null;
	            this.description = null;
	        } else {
	            imgAttribs = new Array("url", "title", "link", "width", "height", "description");
	            for (var i = 0; i < imgAttribs.length; i++)
	                if (imgElement.getAttribute(imgAttribs[i]) != null)
	                eval("this." + imgAttribs[i] + "=imgElement.getAttribute(" + imgAttribs[i] + ")");
	        }
	    }
	    function RSS2Category(catElement) {
	        if (catElement == null) {
	            this.domain = null;
	            this.value = null;
	        } else {
	            this.domain = catElement.getAttribute("domain");
	            if (catElement.childNodes.lenght > 0) this.value = catElement.childNodes[0].nodeValue;
	            else this.value = "";
	        }
	    } 
	    function RSS2Item(itemxml) {
	
	        /*A*/
	        /*required properties (strings)*/
	        this.title;
	        this.link;
	        this.description;

	        /*optional properties (strings)*/
	        this.author;
	        this.comments;
	        this.pubDate;

	        /*optional properties (objects)*/
	        this.category;
	        this.enclosure;
	        this.guid;
	        this.source;

	        /*B*/
	        var properties = new Array("title", "link", "description", "author", "comments", "pubDate");
	        var tmpElement = null;
	        for (var i = 0; i < properties.length; i++) {
	            tmpElement = itemxml.getElementsByTagName(properties[i])[0];
	            if (tmpElement != null)
	                eval("this." + properties[i] + "=tmpElement.childNodes[0].nodeValue");
	        }

	        /*C*/
	        this.category = new RSS2Category(itemxml.getElementsByTagName("category")[0]);
	        this.enclosure = new RSS2Enclosure(itemxml.getElementsByTagName("enclosure")[0]);
	        this.guid = new RSS2Guid(itemxml.getElementsByTagName("guid")[0]);
	        this.source = new RSS2Source(itemxml.getElementsByTagName("source")[0]);
	    }
	    function RSS2Guid(guidElement) {
	        if (guidElement == null) {
	            this.isPermaLink = null;
	            this.value = null;
	        } else {
	            this.isPermaLink = guidElement.getAttribute("isPermaLink");
	            this.value = guidElement.childNodes[0].nodeValue;
	        }
	    }

	    function RSS2Source(souElement) {
	        if (souElement == null) {
	            this.url = null;
	            this.value = null;
	        } else {
	            this.url = souElement.getAttribute("url");
	            this.value = souElement.childNodes[0].nodeValue;
	        }
	    }
	    function RSS2Channel(rssxml) {
	        /*A*/
	        /*required string properties*/
	        this.title;
	        this.link;
	        this.description;

	        /*optional string properties*/
	        this.language;
	        this.copyright;
	        this.managingEditor;
	        this.webMaster;
	        this.pubDate;
	        this.lastBuildDate;
	        this.generator;
	        this.docs;
	        this.ttl;
	        this.rating;

	        /*optional object properties*/
	        this.category;
	        this.image;

	        /*array of RSS2Item objects*/
	        this.items = new Array();

	        /*B*/
	        var chanElement = rssxml.getElementsByTagName("channel")[0];
	        var itemElements = rssxml.getElementsByTagName("item");

	        /*C*/
	        for (var i = 0; i < itemElements.length; i++) {
	            Item = new RSS2Item(itemElements[i]);
	            this.items.push(Item);
	        }

	        /*D*/
	        var properties = new Array("title", "link", "description", "language", "copyright", "managingEditor", "webMaster", "pubDate", "lastBuildDate", "generator", "docs", "ttl", "rating");
	        var tmpElement = null;
	        for (var i = 0; i < properties.length; i++) {
	            tmpElement = chanElement.getElementsByTagName(properties[i])[0];
	            if (tmpElement != null)
	                eval("this." + properties[i] + "=tmpElement.childNodes[0].nodeValue");
	        }

	        /*E*/
	        this.category = new RSS2Category(chanElement.getElementsByTagName("category")[0]);
	        this.image = new RSS2Image(chanElement.getElementsByTagName("image")[0]);
	    }

	    function showRSS(RSS) {
	        /*A*/
	        var imageTag = "<img id='chan_image'";
	        var startItemTag = "<div id='item'>";
	        var startTitle = "<div id='item_title'>";
	        var startLink = "<div id='item_link'>";
	        var startDescription = "<div id='item_description'>";
	        var endTag = "</div>";

	        /*B*/
	        var properties = new Array("title", "link", "description", "pubDate", "copyright");
	        for (var i = 0; i < properties.length; i++) {
	            eval("document.getElementById('chan_" + properties[i] + "').innerHTML = ''"); /*B1*/
	            curProp = eval("RSS." + properties[i]);
	            if (curProp != null)
	                eval("document.getElementById('chan_" + properties[i] + "').innerHTML = curProp"); /*B2*/
	        }

	        /*C*/
	        /*show the image*/
	        document.getElementById("chan_image_link").innerHTML = "";
	        if (RSS.image.src != null) {
	            document.getElementById("chan_image_link").href = RSS.image.link; /*C1*/
	            document.getElementById("chan_image_link").innerHTML = imageTag
            + " alt='" + RSS.image.description
            + "' width='" + RSS.image.width
            + "' height='" + RSS.image.height
            + "' src='" + RSS.image.url
            + "' " + "/>"; /*C2*/
	        }


	        /*D*/
	        document.getElementById("chan_items").innerHTML = "";
	        for (var i = 0; i < RSS.items.length; i++) {
	            item_html = startItemTag;
	            item_html += (RSS.items[i].title == null) ? "" : startTitle + RSS.items[i].title + endTag;
	            item_html += (RSS.items[i].link == null) ? "" : startLink + RSS.items[i].link + endTag;
	            item_html += (RSS.items[i].description == null) ? "" : startDescription + RSS.items[i].description + endTag;
	            item_html += endTag;
	            document.getElementById("chan_items").innerHTML += item_html; /*D1*/
	        }

	        return true;
	    }

	    var Utf8 = {

	        // public method for url encoding
	        encode: function(string) {
	            string = string.replace(/\r\n/g, "\n");
	            var utftext = "";

	            for (var n = 0; n < string.length; n++) {

	                var c = string.charCodeAt(n);

	                if (c < 128) {
	                    utftext += String.fromCharCode(c);
	                }
	                else if ((c > 127) && (c < 2048)) {
	                    utftext += String.fromCharCode((c >> 6) | 192);
	                    utftext += String.fromCharCode((c & 63) | 128);
	                }
	                else {
	                    utftext += String.fromCharCode((c >> 12) | 224);
	                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
	                    utftext += String.fromCharCode((c & 63) | 128);
	                }

	            }

	            return utftext;
	        },

	        // public method for url decoding
	        decode: function(utftext) {
	            var string = "";
	            var i = 0;
	            var c = c1 = c2 = 0;

	            while (i < utftext.length) {

	                c = utftext.charCodeAt(i);

	                if (c < 128) {
	                    string += String.fromCharCode(c);
	                    i++;
	                }
	                else if ((c > 191) && (c < 224)) {
	                    c2 = utftext.charCodeAt(i + 1);
	                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
	                    i += 2;
	                }
	                else {
	                    c2 = utftext.charCodeAt(i + 1);
	                    c3 = utftext.charCodeAt(i + 2);
	                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
	                    i += 3;
	                }

	            }

	            return string;
	        }

	    }   
              
	    </script>
	</body>
</html>